Make the COPARTITION keyword reserved#15734
Conversation
COPARTITION is a keyword specific to table functions.
It is neither reserved nor non-reserved according to SQL spec of 2016.
Before this change, COPARTITION was a non-reserved word, leading to
a failure in a case like:
SELECT * FROM TABLE(system.test_inputs_function(
input_1 => TABLE(VALUES 1, 2, 3),
input_2 => TABLE(VALUES 1, 1, null, null, 2, 2) t2(x2) PARTITION BY x2,
input_3 => TABLE(VALUES null, 2, 2, 2, 3) t3(x3) PARTITION BY x3,
input_4 => TABLE(VALUES 4, 5)
COPARTITION (t2, t3)))
because the COPARTITION clause was parsed as a table alias.
|
Is this an error in the SQL specification? Or is it possible to change the parsing so that it is only reserved in table function contexts? This would be the first instance of a reserved keyword in Trino that isn't reserved in the SQL specification. |
|
@electrum I tried to find the information about It is likely though that cc @martint |
|
I'm closing this in favor of #16014 |
Final SQL Parsing changes for TVF. Includes changes for unaliasing as well as a change to prevent COPARTITION ambiguity. Please check trinodb/trino#15734 for more details. Contains all changes under `presto-parser/src/main/java/com/facebook/presto/sql` New complete PR: #26188 ## Description <!---Describe your changes in detail--> Changes adapted from trino/PR#16014, 14175 ## Motivation and Context <!---Why is this change required? What problem does it solve?--> <!---If it fixes an open issue, please link to the issue here.--> The keyword COPARTITION is specific to table function invocation. It is not a reserved keyword. In some cases, the word COPARTITION can be ambiguously interpreted: either as table argument alias, or as part of the COPARTITION clause. To solve the ambiguity, we decided to fail queries using the word "copartition" as table argument alias, while keeping the word non-reserved and available to be used as identifier in other contexts. ## Test Plan <!---Please fill in how you tested your change--> testCopartitionInTableArgumentAlias in TestSqlParser.java Tests ran to check for regressions: TestSqlParser TestSqlParserErrorHandling TestAnalyzer TestTableFunctionInvocation TestTableFunctionRegistry ``` == NO RELEASE NOTE == ``` Co-authored-by: kasiafi <30203062+kasiafi@users.noreply.github.com> Co-authored-by: Xin Zhang <desertsxin@gmail.com>
COPARTITION is a keyword specific to table functions. It is neither reserved nor non-reserved according to SQL spec of 2016. Before this change, COPARTITION was a non-reserved word, leading to a failure in a case like:
SELECT * FROM TABLE(system.test_inputs_function(
input_1 => TABLE(VALUES 1, 2, 3),
input_2 => TABLE(VALUES 1, 1, null, null, 2, 2) t2(x2) PARTITION BY x2,
input_3 => TABLE(VALUES null, 2, 2, 2, 3) t3(x3) PARTITION BY x3,
input_4 => TABLE(VALUES 4, 5)
COPARTITION (t2, t3)))
because the COPARTITION clause was parsed as a table alias.
Release notes
(X) This is not user-visible or docs only and no release notes are required.
Table arguments are not yet supported. But maybe we should document the reserved word?
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text: